import sys
import subprocess
from datetime import datetime

def main():
    if len(sys.argv) != 3:
        print("用法: python3 run_pipeline.py <图片路径> <current_time>")
        sys.exit(1)
    image_path = sys.argv[1]
    
    time_string = sys.argv[2]
    
    #time_string = current_time.strftime("%Y-%m-%d_%H:%M:%S")
    
    # 步骤1: 调用 request_body_Cut.py 并保存结果到 cut.json
    with open(time_string+"_cut.json", "w") as f:
  
        subprocess.run(
            ["python3", "request_body_Cut.py", image_path, time_string],
            stdout=f,
            check=True
        )
    
    # 步骤2: 格式化 JSON
    subprocess.run(["python3", "maintain_json.py", time_string], check=True)
    
    # 步骤3: 进一步处理 JSON
    subprocess.run(["python3", "import json.py",time_string], check=True)
    
    print("处理完成！最终输出文件: normalize_json.json")
    
    subprocess.run(["python3","pic_cut.py",time_string+"_normalize_json.json",image_path,time_string+"_output_subjects/",time_string+"_response.json"],check = True)
    print("切割完成")

if __name__ == "__main__":
    main()
